package edu.neusoft.kongfanfei317.yuejian1.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.squareup.picasso.Picasso;

import java.util.List;

import edu.neusoft.kongfanfei317.yuejian1.activity.MasterDetailsActivity;
import edu.neusoft.kongfanfei317.yuejian1.activity.MasterListActivity;
import edu.neusoft.kongfanfei317.yuejian1.bean.CollectListBean;


public class AllCollectAdapter extends BaseAdapter<CollectListBean>{//flag 0 店铺 flag 1 菜品
    public AllCollectAdapter(Context context, List<CollectListBean> items, int layoutResource) {
        super(context, items, layoutResource);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        final String id = items.get(position).getShop_id();
        final String shopname = items.get(position).getShopname();
        String shopaddress = items.get(position).getAddress();

        final String flag = items.get(position).getFlag();

        if(flag.equals("0")) {
            viewHolder.tv_name.setText(shopname);
            viewHolder.tv_address.setText(shopaddress);
            Picasso.with(context).load(items.get(position).getPic()).into(viewHolder.img);
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Log.i("TEST", "onClick: ");
                    Intent intent = new Intent(context, MasterListActivity.class);
                    intent.putExtra("id", id);
                    intent.putExtra("shopname", shopname);
                    context.startActivity(intent);

                }
            });
            //点击事件
        }
        else{
            final String foodid = items.get(position).getFood_id();
            final String foodname = items.get(position).getFoodname();
            final String shop_id=items.get(position).getShop_id();
//            final String type_id =items.get(position).getType_id();
//
//          final String foodintro = items.get(position).getIntro();
            final String foodprice = items.get(position).getPrice();
            final String foodimg = items.get(position).getPic();

            String price = items.get(position).getPrice();
            viewHolder.tv_name.setText(foodname);
            viewHolder.tv_address.setText(price);
            Picasso.with(context).load(items.get(position).getPic()).into(viewHolder.img);
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Log.i("TEST", "onClick: ");
                    Intent intent = new Intent(context, MasterDetailsActivity.class);
                    //intent.putExtra("foodid", foodid);
                    //intent.putExtra("foodname", foodname);

                    intent.putExtra("shop_id",shop_id);
                    intent.putExtra("foodname",foodname);
//                    intent.putExtra("foodintro",foodintro);
                    intent.putExtra("foodprice",foodprice);
                    intent.putExtra("foodimg",foodimg);
                    intent.putExtra("foodid",foodid);
//                    intent.putExtra("typeid",type_id);
                    context.startActivity(intent);

                }
            });

        }
    }
}
